<%@ page language="java" pageEncoding="UTF-8" contentType="text/html;charset=UTF-8" %>
<%@ include file="/resources/modular/plugin/taglibs.jsp" %>
<!doctype html>
<head content="-优惠码">
    <%@ include file="/resources/modular/head/inside_head.jsp" %>
</head>
<body class="GC_Menu_6" name="GC_promocode">
<%@ include file="/resources/modular/plugin/mainMenu.jsp" %>
<div class="page">
    <%@ include file="/resources/modular/plugin/mainTopMenu.jsp" %>
    <div class="page_left">
        <ul class="combopage_leftu1">
            <li><a href="javascript:;">未使用</a></li>
            <li><a href="javascript:;">已使用</a></li>
            <li><a href="javascript:;">已过期</a></li>
        </ul>
    </div>
    <div class="page_right">
        <div class="promocode_inner">

            <%@ include file="/resources/modular/plugin/PromoCodeAddTab.jsp" %>

            <div id="add_single" class="promocode_add_details promocode_add_dv1">
                <p class="promocode_add_detailsnumb">
                    <span>优惠套餐：</span>
                    <input type="number" class="promocode_add_number" placeholder="请输入币数">
                    <span>币</span></p>

                <p class="promocode_add_detailstime">
                    <span>有效时间：</span>
                    <input class="Wdate" type="text" onClick="WdatePicker()" placeholder="请设置开始时间">
                    <span>至</span>
                    <input class="Wdate" type="text" onClick="WdatePicker()" placeholder="请设置结束时间">
                </p>

                <div style="height:70px;"><a id="addbtn_single" class="promocode_addbtn1" href="javascript:;">确认</a></div>
            </div>

            <div id="add_batch" class="promocode_add_details promocode_add_dv2" style="display: none;">
                <p class="promocode_add_detailsnumb">
                    <span>优惠套餐：</span>
                    <input type="number" class="promocode_add_number" placeholder="请输入币数">
                    <span>币</span></p>
                <p class="promocode_add_detailstime">
                    <span>有效时间：</span>
                    <input class="Wdate" type="text" onClick="WdatePicker()" placeholder="请设置开始时间">
                    <span>至</span>
                    <input class="Wdate" type="text" onClick="WdatePicker()" placeholder="请设置结束时间">
                </p>
                <p class="promocode_add_detailsnumb">
                    <span>数量：</span>
                    <input type="number" class="promocode_add_batchnumber" placeholder="请输入数量">
                </p>
                <div style="height:70px;"><a id="addbtn_batch" class="promocode_addbtn2" href="javascript:;">确认</a></div>
            </div>
        </div>
    </div>
</body>

<script type="application/javascript">
    $("#GC_promocode_singleadd").on("click",function(){
        $("#add_batch").hide();
        $("#GC_promocode_batchadd").removeClass("cur");
        $("#add_single").show();
        $("#GC_promocode_singleadd").addClass("cur");
    })

    $("#GC_promocode_batchadd").on("click",function(){
        $("#add_single").hide();
        $("#GC_promocode_singleadd").removeClass("cur");
        $("#add_batch").show();
        $("#GC_promocode_batchadd").addClass("cur");
    })

    $(".combopage_leftu1 a").each(function (index) {
        $(this).click(function () {
            window.location.href = "${basePath}v2/promocode/showView";
        })
    });

    $("#addbtn_single").on("click", function(){
        var coin = $("#add_single .promocode_add_detailsnumb input:eq(0)").val();
        var startDate = $("#add_single .promocode_add_detailstime input:eq(0)").val();
        var endDate = $("#add_single .promocode_add_detailstime input:eq(1)").val();
        var count = 1;

        if (!$(".promocode_addbtn1").hasClass("cur")){
            return;
        }

        $.ajax({
            url: '${basePath}v2/promocode/add',
            type: 'POST',
            data: {
                coin: coin,
                startDate: startDate,
                endDate: endDate,
                count: count
            },
            success: function (ret) {
                alert(ret.info);
            }
        });
    })

    $("#addbtn_batch").on("click", function(){
        var coin = $("#add_batch .promocode_add_detailsnumb input:eq(0)").val();
        var startDate = $("#add_batch .promocode_add_detailstime input:eq(0)").val();
        var endDate = $("#add_batch .promocode_add_detailstime input:eq(1)").val();
        var count = $("#add_batch .promocode_add_detailsnumb input:eq(1)").val();

        if (!$(".promocode_addbtn2").hasClass("cur")){
            return;
        }

        $.ajax({
            url: '${basePath}v2/promocode/add',
            type: 'POST',
            data: {
                coin: coin,
                startDate: startDate,
                endDate: endDate,
                count: count
            },
            success: function (ret) {
                alert(ret.info);
            }
        });
    })


    //单个优惠券添加确认按钮
    $(".promocode_add_dv1 input").on("keyup focus", function(){
        var promocode_addnumb=parseInt($(".promocode_add_dv1 input").eq(0).val());
        var promocode_addtime1=$(".promocode_add_dv1 input").eq(1).val();
        var promocode_addtime2=$(".promocode_add_dv1 input").eq(2).val();
        if(promocode_addnumb!="" && promocode_addnumb>0 && promocode_addtime1!="" && promocode_addtime2!=""){
            $(".promocode_addbtn1").addClass("cur");
        }else{
            $(".promocode_addbtn1").removeClass("cur");
        }
    });

    //批量优惠券添加确认按钮
    $(".promocode_add_dv2 input").on("keyup focus", function(){
        var promocode_addnumb=parseInt($(".promocode_add_dv2 input").eq(0).val());
        var promocode_addtime1=$(".promocode_add_dv2 input").eq(1).val();
        var promocode_addtime2=$(".promocode_add_dv2 input").eq(2).val();
        var promocode_addcodenumb=parseInt($(".promocode_add_dv2 input").eq(3).val());
        if(promocode_addnumb!="" && promocode_addnumb>0 && promocode_addtime1!="" && promocode_addtime2!="" && promocode_addcodenumb!="" && promocode_addcodenumb>0){
            $(".promocode_addbtn2").addClass("cur");
        }else{
            $(".promocode_addbtn2").removeClass("cur");
        }
    });
</script>

</html>
<%@ include file="/resources/modular/foot/inside_footer.jsp" %>
